//
//  BKFunctionView.m
//  FastBee
//
//  Created by mac on 16/9/10.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "BKFunctionView.h"
#import "masonry.h"
#import "BKButton.h"
#import "UIView+MDRExtension.h"
#import <UIButton+WebCache.h>
#import "BKFunctionModel.h"

@interface BKFunctionView()
@property (nonatomic,weak) UIButton *iconBtn;
@property (nonatomic,strong) NSMutableArray *buttonArr;

@end

@implementation BKFunctionView

- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (NSMutableArray *)arrM{

    if (_arrM == nil) {
        
        _arrM = [NSMutableArray array];
    }
    return _arrM;
}

-(NSMutableArray *)buttonArr
{
    if (_buttonArr == nil) {
        _buttonArr = [NSMutableArray array];
    }
    return _buttonArr;
}

- (void)setupUI{
    
    for (int i = 0; i<4; ++i) {
        
        CGFloat itemWidth = 80;
        CGFloat itemHeight = 90;
        CGFloat margin = (self.width - 4 *itemWidth)/5;
        
        BKButton *iconBtn = [[BKButton alloc]initWithFrame:CGRectMake(margin+(margin + itemWidth)*i, 10, itemWidth, itemHeight)];
        iconBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [iconBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.buttonArr addObject:iconBtn];

        [self addSubview:iconBtn];
    }
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    if (self.arrM.count) {
        for (NSInteger i = 0; i < self.buttonArr.count; i++) {
            
            BKFunctionModel *model = self.arrM[i];
            BKButton *button = self.buttonArr[i];

            
            [button sd_setImageWithURL:[NSURL URLWithString:model.img] forState:UIControlStateNormal];
//            [button setImage:[UIImage imageNamed:@"dao"] forState:UIControlStateNormal];
            [button setTitle:model.name forState:UIControlStateNormal];
            
        }
    }
}



@end
